#pragma once

#include "TcpSocket.hpp"

class TcpConnectSocket
{
public:
    TcpConnectSocket(std::string serverIp, uint16_t serverPort)
    {
        _socket = new TcpSocket();
        _socket->createConnectSocket(serverIp, serverPort);
    }

    TcpConnectSocket(Socket* tcpSocket)
    {
        _socket = tcpSocket;
    }

    ssize_t readStream(std::string& stream)
    {
        char requestBuffer[1024];
        ssize_t n = ::read(_socket->getSocketFd(), requestBuffer, sizeof(requestBuffer)-1);
        requestBuffer[n] = '\0';
        stream = requestBuffer;
        return n;
    }

    ssize_t writeStream(const std::string& stream)
    {
        return ::write(_socket->getSocketFd(), stream.c_str(), stream.size());
    }

    void connect(std::string& serverIp, uint16_t serverPort)
    {
        _socket->connect(serverIp, serverPort);
    }

    ~TcpConnectSocket()
    {}
private:
    Socket* _socket;
};